package taskshare.controller;

import java.util.Date;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import taskshare.meta.CommentMeta;
import taskshare.meta.TaskMeta;
import taskshare.model.Comment;
import taskshare.model.Task;
import taskshare.service.TaskService;

public class AddcommentController extends Controller {

    TaskMeta tm = TaskMeta.get();
    CommentMeta cm = CommentMeta.get();

    TaskService taskService = new TaskService();
    UserService userService = UserServiceFactory.getUserService();

    @Override
    public Navigation run() throws Exception {
        Task task = taskService.get(asKey(tm.key));

        Comment comment = new Comment();
        comment.setContent(asString(cm.content));
        comment.setDate(new Date());
        comment.setUser(userService.getCurrentUser());
        task.getCommentList().add(comment);

        taskService.put(task);

        return redirect(basePath);
    }
}
